package cn.kgm.template.server.controller;

import cn.kgm.core.http.request.BaseController;
import cn.kgm.core.jackson.JsonUtil;
import cn.kgm.template.server.entity.TemplateOptions;
import cn.kgm.template.server.service.TemplateOptionsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * # 技术改变自己 #
 * 模板数据,选择项表
 * @author kapp-i
 * @date   2024-03-18 15:36:57
 */
@Slf4j
@SpringBootTest
class TemplateOptionsTestService extends BaseController {

    @Autowired
    private TemplateOptionsService templateOptionsService;

    @Test
    void page() {
        IPage<TemplateOptions> page = getPage();
        LambdaQueryWrapper<TemplateOptions> wrapper = Wrappers.lambdaQuery(TemplateOptions.builder()
                .build());
        IPage<TemplateOptions> pages = templateOptionsService.page(page, wrapper);
        log.info("TemplateOptionsTestService::page===>{}", JsonUtil.toJson(pages.getRecords()));
    }

    @Test
    void get() {
        Long id = 1L;
        TemplateOptions templateOptions =templateOptionsService.getById(id);
        log.info("TemplateOptionsTestService::get===>{}", JsonUtil.toJson(templateOptions));
    }

    @Test
    void save() {
        TemplateOptions templateOptions = TemplateOptions.builder()
                .build();
            templateOptionsService.save(templateOptions);
        log.info("TemplateOptionsTestService::save===>{}", JsonUtil.toJson(templateOptions));
    }

    @Test
    void update() {
        TemplateOptions templateOptions = TemplateOptions.builder()
                .build();
            templateOptionsService.updateById(templateOptions);
        log.info("TemplateOptionsTestService::update===>{}", JsonUtil.toJson(templateOptions));
    }

    @Test
    void delete() {
        Long[] ids = new Long[]{0L};
            templateOptionsService.update(Wrappers.<TemplateOptions>lambdaUpdate()
                .set(TemplateOptions::getIsDel, true)
                .in(TemplateOptions::getId, ids));
        log.info("TemplateOptionsTestService::delete===>{}", JsonUtil.toJson(ids));
    }
}
